import {observable, autorun, computed, action} from 'mobx';
import {getData} from './service';
import AbstractAction from "../AbstractAction";
import Rule from "./rule";
import {set as _set} from 'lodash';

export default class Actions extends AbstractAction {
    constructor(state) {
        super();
        this.state = state;
        this.rule = new Rule(state);
    }

    @action.bound print() {
        alert(this.state.age);
    }

    @action.bound add() {
        this.state.testList = [{id:1,name:'test1'},{id:1,name:'test1'},{id:1,name:'test1'}]
        // this.history.push('/home');
    }

    @action.bound
    async getData() {
        const response = await getData();
        // console.log(response,111);
        this.state.data = response.data.data;
    }

    @action.bound bindSet = valuePath => (e) => {
        if (e && e.target) {
            _set(this.state, valuePath, e.target.value);
        } else {
            _set(this.state, valuePath, e);
        }
    };
}
